﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddAdjustingPage.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.FTradeModel.AddAdjustingPage" %>
<%--调帐页面--%>
<script type="text/javascript">
    function validateCallbackAddAdjustingPage(form, callback) {
        var $form = $(form);
        $("#AddAdjustingPagebtnSave").find("button").attr("disabled", "disabled").html("保存中......");
        setTimeout(function () { $("#AddAdjustingPagebtnSave").find("button").removeAttr("disabled").html(" 保 存 "); }, 20000);
        //  return false;
        return validateCallback(form, callback);
    }
</script>
<div class="pageContent">
	<form  method="post" action="FTradeModel/AddAdjustingPage.aspx?ajaxmethod=add" class="pageForm required-validate" onsubmit="return validateCallbackAddAdjustingPage(this, navTabAjaxDone);" >
		<div class="pageFormContent" layoutH="56">
            <h2 style="clear:both; padding:5px; border-bottom:1px solid #B8D0D6; margin-bottom:5px; ">
                调帐操作说明:
            </h2>
            <div style=" line-height:23px;clear:both; padding:5px; border:1px solid #B8D0D6;margin-bottom:5px; ">
                <input type="hidden" name="JingXiaoShang" id="AddAdjustingPage_JingXiaoShang" readonly />
                1.先选择需调帐的&nbsp;<a href="javascript:openSelectAddAdjustingPage()" style="color:Red;" >经销商</a>:<span id="AddAdjustingPage_JingXiaoShang_span"></span><br/>
                2.可按　已冲帐　的收款记录,或按机号　进行<a href="javascript:openWhereAddadjustingPage()" style="color:Red;">&nbsp;查找&nbsp;</a>,以选择要调帐的记录.<br/>
                3.确认　调帐金额,提交保存即可.  <br/>
                
            </div>

            <h2 style="clear:both; padding:5px; border-bottom:1px solid #B8D0D6; margin-bottom:5px; margin-top:15px; line-height:26px;">
                本次调帐记录列表
            </h2>
            <table id="AddAdjustingPage_AdjustingList" class="list" width="100%" layouth="90" >
                <thead>
                    <tr  >                
                        <th width="80" >机号</th>
                        <th>收款标题</th>
                        <th>冲帐金额</th> 
                        <th>本次调帐</th>
                        <th>记账日期</th> 
                        <th>冲帐款项</th>                
                        <th width="80">应付金额</th> 
                        <th width="120">到期日</th> 
                        <th>已付金额</th> 
                        <th>删除</th> 
                                   
                    </tr>
                 </thead>
                 <tbody>
                    <%--<tr >
				        <td><input type="text" readonly value="[机号]" /></td>
                        <td><input type="text" readonly value="[收款标题]" /></td>
				        <td><input type="text" readonly value="[冲帐款项]" /></td>
                        <td>本次调帐</td>
				        <td><input type="text" readonly value="[金额]" /></td>
                        <td><input type="text" readonly value="[到期日]" /></td>
                        <td><input type="text" readonly value="[已付]" /></td>
                        <td>
                            <input type="hidden" name="FbalanceId" value="[冲帐ID]" />
                            <input type="text" name="BalanceMoney" value="[冲帐金额]" />
                        </td>
			            <td>
					        <a href="javascript:onAddAdjustingPageDelete(this)" title="删除">删除</a>
				        </td>
			        </tr>--%>
                 </tbody>
                 <tfoot>
                    <tr>
                        <td style="text-align:right;" colspan="3">
                        
                        本次调帐总金额:
                        </td>
                        <td colspan="7" >
                            <input type="text" name="AllBalance"  id="AddAdjustingPage_AllBalance" size="10"  value="0" class="required inputFloat" />      
                            &nbsp;
                            <span style="color:Red; line-height:25px;" id="AddAdjustingPage_AllBalance_Hit"></span>                      
                        </td>
                        
                    </tr>
                 </tfoot>
               </table>
               <script>
                   //打开选择经销商窗口
                   function openSelectAddAdjustingPage() {
                       var rel = "AddAdjustingPageSelectAgent";
                       var url = "FTradeModel/AddAdjustingPageStep1.aspx";
                       var title = "1.选择经销商";
                       var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
                       top.$.pdialog.open(url, rel, title, options);
                   }
                   //打开选择条件窗口
                   function openWhereAddadjustingPage() {
                       var agentName = $("#AddAdjustingPage_JingXiaoShang").val();
                       //打开冲帐记录查询窗口
                       var rel = "AddAdjustingPageSelectAgent";
                       var url = "FTradeModel/AddAdjustingPageStep2.aspx?JingXiaoShang=" + encodeURI(agentName);
                       var title = "2.选择[" + agentName + "]可调帐的记录";
                       var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
                       top.$.pdialog.open(url, rel, title, options);
                       //
                       
                   }
                   //选中经销商
                   function onAddAdjustingPageSelectJingXiaoShang(agentName) {
                       $("#AddAdjustingPage_JingXiaoShang").val(agentName);
                       $("#AddAdjustingPage_JingXiaoShang_span").html(agentName);
                       openWhereAddadjustingPage();
                   }
                   //删除选中的冲帐记录
                   function onAddAdjustingPageDelete(aObj) {
                       aObj.closest("tr").remove();
                       onAddAdjustingPageChange();
                   }
                   //总调帐金额
                   function onAddAdjustingPageChange() {
                       var $AdjustingList = $("#AddAdjustingPage_AdjustingList").find("tbody");
                       var AllBalance = 0;
                       $AdjustingList.find("input[name='AdjustingMoney']").each(function () {
                           // var $AllBalance = $("#FTradeBalanceAdd_AddBalanceList_AllBalance").val();
                           AllBalance = AllBalance + parseFloat($(this).val());
                       })
                       var $AddAdjustingPage_AllBalance = $("#AddAdjustingPage_AllBalance");
                       $AddAdjustingPage_AllBalance.val(AllBalance); //
                       //
                       if (AllBalance > 0) {
                           $("#AddAdjustingPagebtnSave").show();
                       }
                       else {
                           $("#AddAdjustingPagebtnSave").hide();
                        }


                   }
                   ///选择冲帐记录
                   function onSelectSingRowBalance(obj,rowDate) {
                      
                       //alert(rowDate.FbalanceId);
                       var $AdjustingList = $("#AddAdjustingPage_AdjustingList").find("tbody");
                       var rowExist = $AdjustingList.find("#AdjustingList_Row" + rowDate.FbalanceId).attr("id");
                       if (rowExist != undefined) {                          
                           $(obj).attr("checked", "")                          
                           $("#AdjustingList_Row" + rowDate.FbalanceId).remove();
                       }
                       else {
                           $(obj).attr("checked", "checked");

                           $(obj).closest("tr").css("color", "red");
                           $(obj).remove();

                           var htmltemp = "<tr id='AdjustingList_Row" + rowDate.FbalanceId + "' >" +
				                    "<td>[机号]</td>" +
                                    "<td>[收款标题]</td>" +
                                    "<td>[冲帐金额]</td>" +
                                    "<td><input type=\"hidden\" name=\"oldAdjustingMoney\" value=\"[可调帐金额2]\" />"+
                                    "<input type=\"text\" size='10' name=\"AdjustingMoney\" value=\"[可调帐金额]\" class='inputFloat' /></td>" +
				                    "<td>[记账日期]</td>" +
				                    "<td>[冲帐款项]</td>" +
                                    "<td>[金额]</td>" +
                                    "<td>[到期日]</td>" +
                                    "<td>" +
                                     "   <input type=\"hidden\" name=\"FCatheringId\" value=\"[收款ID]\" />" +
                                    "    <input type=\"hidden\" name=\"FbalanceId\" value=\"[冲帐ID]\" />" +
                                    "    [已付金额]" +
                                    "</td>" +
			                        "<td>" +
					                "    <a href=\"#\" title=\"删除\">删除</a>" +
				                    "</td>" +
			                    "</tr>";
                           var addHtml = htmltemp.replace("[机号]", rowDate.JiHao).replace("[收款标题]", rowDate.FCTitle).replace("[冲帐金额]", rowDate.BalanceMoney).replace("[记账日期]", rowDate.CreateDate).replace("[冲帐款项]", rowDate.ShowTitle).replace("[金额]", rowDate.JinE).replace("[到期日]", rowDate.DaoQiRi).replace("[已付金额]", rowDate.YiChongJinE).replace("[冲帐ID]", rowDate.FbalanceId).replace("[可调帐金额]", rowDate.AdjustingMoney).replace("[可调帐金额2]", rowDate.AdjustingMoney).replace("[收款ID]", rowDate.FCatheringId);
                           $AdjustingList.append($(addHtml).find("a").click(function () {
                               onAddAdjustingPageDelete($(this));
                           }).end().find("input[name='AdjustingMoney']").blur(function () {

                               var $maxmoney = parseFloat(rowDate.AdjustingMoney);
                               var $inputmoney = parseFloat($(this).val());
                               if ($inputmoney <= 0) {
                                   alert("你所输入的调帐金额小于0,请重输");
                                   $(this).val("0");
                                   return false;
                               }
                               if ($inputmoney > $maxmoney) {
                                   alert("你所输入的调帐金额大于可调帐金额[" + $maxmoney + "],请重输");
                                   $(this).val($maxmoney)
                                   return false;
                               }
                               onAddAdjustingPageChange()
                           }).end()
                           );
                       }
                       //
                       $("#AddAdjustingPage_AdjustingList").find("input.inputFloat").inputFloat();
                       ///
                       onAddAdjustingPageChange();
                   }
                   //
                   $(document).ready(function () {
                       openSelectAddAdjustingPage();
                       $("#AddAdjustingPagebtnSave").hide();
                   })
               </script>
        </div>
		<div class="formBar">
			<ul>
				
				<li id="AddAdjustingPagebtnSave"><div class="buttonActive"><div class="buttonContent"><button type="submit"  >保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>